{	Problem: http://codeforces.ru/problemset/problem/63/C
 	Verdict: Accepted
}
uses SysUtils;
var 
    i,n,sm,bull,cow,r,k,j:longint;
    s,rr:string;
    a,b,c:array[0..15] of longint;
    aa:array[0..15] of string;
begin
read(n);
rr:='0123';
r:=0;
for i:=1 to n do begin
    read(a[i],b[i],c[i]);
    aa[i]:=inttostr(a[i]);
    if a[i]<1000 then aa[i]:='0'+aa[i];
end;
for i:=123 to 9876 do begin
    s:=inttostr(i);
    if i<1000 then s:='0'+s;
    if (s[1]=s[2]) or (s[1]=s[3]) or (s[1]=s[4]) or (s[2]=s[3]) or (s[2]=s[4]) or (s[3]=s[4]) then 
        continue;
    sm:=0;
    for j:=1 to n do begin
        bull:=0;
        cow:=0;
        for k:=1 to 4 do begin
            if s[k]=aa[j][k] then inc(bull);
            if (s[k]<>aa[j][k]) and ((s[k]=aa[j][1]) or (s[k]=aa[j][2]) or (s[k]=aa[j][3]) or (s[k]=aa[j][4])) then inc(cow);
        end;
        if (bull=b[j]) and (cow=c[j]) then inc(sm);
    end;
    if sm=n then begin
        inc(r);
        rr:=s;
    end;
end;
if r=0 then write('Incorrect data');
if r>1 then write('Need more data');
if r=1 then write(rr);
end.  